{% extends 'home/base.html' %}


{% block conleft %}
<div class="am-u-md-8 am-u-sm-12">
    <article class="am-article blog-article-p">
        <div class="am-article-hd">
            <h1 class="am-article-title blog-text-center">{{ blog.title }}</h1>
            <p class="am-article-meta blog-text-center">
             
                <span>
                    <a href="#">@{{ blog.user.username }} &nbsp;</a>
                </span>-
                <span>
                    <a href="#">{{ blog.addtime }}</a></span>
            </p>
        </div>
        <div class="am-article-bd">
            {{ blog.context|safe }}   
         
        </div>
    </article>
    <div class="am-g blog-article-widget blog-article-margin">
        <div class="am-u-lg-4 am-u-md-5 am-u-sm-7 am-u-sm-centered blog-text-center">
            <span class="am-icon-tags">&nbsp;</span>
            {% for v in blog.tags %}
            <a href="#">{{ v.name }}</a>
            {% endfor %}
            
            <hr>
            <a href="">
                <span class="am-icon-qq am-icon-fw am-primary blog-icon"></span>
            </a>
            <a href="">
                <span class="am-icon-wechat am-icon-fw blog-icon"></span>
            </a>
            <a href="">
                <span class="am-icon-weibo am-icon-fw blog-icon"></span>
            </a>
        </div>
    </div>
    <hr>
    <div class="am-g blog-author blog-article-margin">
        <div class="am-u-sm-3 am-u-md-3 am-u-lg-2">
            <img src="assets/i/f15.jpg" alt="" class="blog-author-img am-circle"></div>
        <div class="am-u-sm-9 am-u-md-9 am-u-lg-10">
            <h3>
                <span>作者 &nbsp;: &nbsp;</span>
                <span class="blog-color">{{ blog.user.username }}</span></h3>
            <p>{{ blog.user.info|default('这个人很懒,p都没有',true)}}</p>
        </div>
    </div>
    <hr>

    <!-- 判断当前用户是否登录 -->
    <h3>评论内容</h3>
    {% for v in blog.comments %}
        {% if not v.cid %}
            <div class="am-g" style="border: 1px dotted #ccc;">
                <div class="am-u-sm-9 am-u-md-9 am-u-lg-10 ccc">
                    <h4>
                        {% if v.reply == 0%}
                        <span>作者 &nbsp;: &nbsp;</span>
                        {% else %}
                        <span>评论人 &nbsp;: &nbsp;</span>
                        {% endif %}
                      
                        <span class="blog-color author">{{ v.usercs.username }}</span>
                    </h4>
                    <p>{{ v.context }}</p>
                    <p style="float: right">时间:{{ v.addtime }}&nbsp; &nbsp;<a href="#comments" cid="{{ v.id }}" class="commentscid am-btn am-btn-primary am-btn-xs">回复</a></p>
                </div>
                {% for vv in blog.comments %}
                    {% if vv.cid == v.id %}
                        <div class="am-u-sm-9 am-u-md-9 am-u-lg-10 am-fr"  style="border: 1px dotted #ccc;">
                            <h4 style="margin: 0px;">
                                {% if vv.reply == 0%}
                                <span>作者 &nbsp;: &nbsp;</span>
                                {% else %}
                                <span>评论人 &nbsp;: &nbsp;</span>
                                {% endif %}
                                <span class="author">{{ vv.usercs.username }}</span>
                            </h4>
                            <p style="margin: 0px;">{{ vv.context }}</p>
                            <p style="float: right;margin: 0px;">时间:{{ vv.addtime }}&nbsp; &nbsp;</p>
                        </div>
                    {% endif %}
                {% endfor %}
            </div>
        {% endif %}
    {% endfor %}
    


        
        <form action="{{ url_for('home.comments') }}" method="post" class="am-form am-g">
            <h3 class="blog-comment" id="comments">评论</h3>

            {% if session.get('VipUser') %}

            <fieldset>

                <input type="hidden" name="post_id" value="{{ blog.id }}">
                <input type="hidden" name="user_id" value="{{ session['VipUser']['uid'] }}">
                <input type="hidden" name="cid" value="">
                <div class="am-form-group">
                    <textarea name="context" class="" rows="5" placeholder="一字千金"></textarea>
                </div>
                <p>
                    <button type="submit" class="am-btn am-btn-default">发表评论</button></p>
            </fieldset>

            {% else %}
            <center>
                <a href="{{ url_for('home.login') }}?next={{ request.path }}">请先<span style="color:blue;">登录</span>后评价</a>
            </center>

            {% endif %}
        </form>

    <hr>
</div>
<script type="text/javascript">
    // 给回复按钮绑定单击事件
    $('.commentscid').click(function(){
        var cid = $(this).attr('cid')
        var author = $(this).parents('.ccc').find('.author').text()
        // 把获取的id插入到表单中
        $('input[name=cid]').val(cid)
        // 把获取到的名字加入到文本域中显示出来
        $('textarea[name=context]').val('@'+author+':')

    })
</script>
{% endblock %}
